﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Samples.BizTalk.Adapter.Common;
using Microsoft.BizTalk.TransportProxy.Interop;
using Microsoft.BizTalk.Component.Interop;
using System.Xml;

namespace com.fluister.BizTalk0MQAdapter.BizTalk0MQSendAdapter
{
    class BizTalk0MQSendAdapter : AsyncTransmitter
    {
        private static string zmqNamespace = "http://schemas.microsoft.com/BizTalk/2003/0MQ/Messaging/Transports/zmq-properties";

        public BizTalk0MQSendAdapter()
            : base(
                ".Net 0MQ Transmit Adapter",
                "1.0",
                ".NET 0MQ Transmit Adapter",
                "0MQ",
                new Guid("16C3F408-DE97-485A-8DD9-802BDC70DF3B"),
                zmqNamespace, typeof(BizTalk0MQSendAdapterEndpoint), 10)
        {
        }

        protected override IBTTransmitterBatch CreateAsyncTransmitterBatch()
        {
            return new BizTalk0MQSendAdapterBatch(10, zmqNamespace, TransportProxy, this);
        }

        public ConfigProperties CreateProperties(string uri)
        {
            ConfigProperties properties = new BizTalk0MQAdapterProperties(uri);
            return properties;
        }

        protected override void HandlerPropertyBagLoaded ()
        {
            IPropertyBag config = this.HandlerPropertyBag;
            if (null != config)
            {
                XmlDocument handlerConfigDom = ConfigProperties.IfExistsExtractConfigDom(config);
                if (null != handlerConfigDom)
                {
                    BizTalk0MQAdapterProperties.TransmitHandlerConfiguration(handlerConfigDom);
                }
            }
        }
    }
}
